package com.cloud.mall.consume.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.cloud.mall.consume.domain.ErrorLog;
import com.cloud.mall.consume.wechat.config.WechatConf;
import com.cloud.mall.core.bean.MallBeanUtils;
import com.cloud.mall.log.mapper.MallErrorLogMapper;
import com.cloud.mall.log.mapper.SenderContactsMapper;
import com.cloud.mall.log.model.MallErrorLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
@Slf4j
public class DbServiceImpl extends AbstractErrorService {
    @Autowired
    private MallErrorLogMapper mallErrorLogMapper;
    @Autowired
    private SenderContactsMapper senderContactsMapper;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private WechatConf wechatConf;


    @Override
    protected SenderContactsMapper getSenderContactsMapper() {
        return senderContactsMapper;
    }

    @Override
    protected RestTemplate getRestTemplate() {
        return restTemplate;
    }

    @Override
    protected WechatConf getWechatConf() {
        return wechatConf;
    }

    @Override
    protected void saveError(ErrorLog errorLog) {
        try {
            int count=mallErrorLogMapper.insert(MallBeanUtils.dtoToDo(errorLog, MallErrorLog.class));
        } catch (Exception e) {
            e.printStackTrace();
            new Exception("添加错误日志错误");
        }
    }
}
